package com.shanzmoo.db.sys.service.impl;

import cn.hutool.core.util.StrUtil;
import com.shanzmoo.base.exception.OutletOrderException;
import com.shanzmoo.db.sys.entity.SysParamEntity;
import com.shanzmoo.db.sys.mapper.SysParamMapper;
import com.shanzmoo.db.sys.service.ISysParamService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 系统参数表 服务实现类
 * </p>
 *
 * @author Gzhao
 * @since 2020-12-15
 */
@Service
public class SysParamServiceImpl extends ServiceImpl<SysParamMapper, SysParamEntity> implements ISysParamService {

    @Override
    public Character getOutletMark() {
        String value = this.getValue("outlet_mark");
        if (StrUtil.isBlank(value)){
            throw new OutletOrderException("门店订单标记获取异常，请联系开发人员处理");
        }
        char mark = value.charAt(0);

        baseMapper.updateValue("outlet_mark", value.substring(1, value.length()));
        return mark;
    }

    @Override
    public String getValue(String key) {
        return baseMapper.getValue(key);
    }
}
